<?
include("../header.php");
include("../lib/config.php");
$uploaddir 		= getcwd(); // get path 
$upload			= $HTTP_POST_VARS['upload'];
$hapus			= $HTTP_GET_VARS['hapus'];
$file 			= strtolower($_FILES['file']['name']);
$filenya		= $HTTP_GET_VARS['filenya'];
$uploadfile 	= "$uploaddir/../file_download/$file"; //place upload file
$dirimage		= "$uploaddir/../file_download";
$dtime			= date("d m Y H:i:s");
$keys			= md5($dtime);
$_SESSION['key'] = $keys;

$shdok = mssql_query("SELECT * FROM VPrivUser WHERE username='".$_SESSION['user_login']."' AND nama_menu='upload_document'",$conn);
$rhdok = mssql_fetch_array($shdok);	

?>
<form name="FEmployee" enctype="multipart/form-data" method="post" action="<?=$PHP_SELF?>">
<table width="100%" class="no_border">
 <tr>
  <td colspan="2">
	<table width="100%" style="border:none;">
	<tr>
	 <td colspan="2" class="line_bottom">&nbsp;&nbsp;<b>DOWNLOAD FILE</b></td>
	</tr>
	</table>
  </td>
  </td>
 </tr>
 <tr>
  <td>
 <table style="position:relative; left:80px;" cellpadding="4" cellspacing="0">
<?
if($hapus == "yes"){
	echo"
	<tr>
	 <td align=center colspan=2>";
	 if(unlink("$dirimage/$filenya")){
	 	echo"<div width=200 height='50' style='background-color: #EFEFFF;'><bR>File sudah dihapus ... <br><br></div>";
	 }
	 else{
	 	echo"<div width=200 height='50' style='background-color: #EFEFFF;' color: red;'><bR>File tidak bisa dihapus ... <br><br></div>";
	 }
	echo"</td>
	</tr>
	";
}
// jika hak akses tambah file
if($upload == "yes"){
	echo'<tr>
	   <td align="center" colspan="2">';
			if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) 
			{
				echo"<div width=200 height='50' style='background-color: #EFEFFF;'><bR>File sudah diupload ... <br><br></div>";
			}
			else{
				echo"<div width=200 height='50' style='background-color: #EFEFFF; color: red;'><bR>Ukuran file terlalu besar ... <br><br></div>";
			}
		//clearstatcache;
	echo'  </td>
	 </tr>';
}
if($rhdok[tambah] == 1){
?>

 <tr>
  <td align="right">Silahkan upload file: &nbsp;&nbsp;&nbsp;<br />
  <small class="required"><i>Maksimal ukuran file 2MB</i></small>&nbsp;&nbsp;&nbsp;&nbsp;
  </td>
  <td><input type="file" name="file" /><input type="submit" value="Upload" class="button" /><input type="hidden" name="upload" value="yes" /></td>
 </tr>
<?
}
?>
</table>
</form>
<fieldset>
 <legend>Daftar file</legend>
 <table width="100%">
 <?
	$d = dir($dirimage);
	while (false !== ($entry = $d->read())) {
		if($entry == "." || $entry == ".."){
		}
		else{
			echo"<tr>
			   <td width=80%>&bull; <a href='frm_download_file.php?key=$keys&amp;file=$entry' target='_blank'>$entry</a></td>
			   <td>";
			if($rhdok[hapus] == 1){
				echo"<a href='#' onclick='Javascript:del_file(\"$entry\");'><img src='../images/b_delete.png' border='0'></a>";
			}
			else{
				echo"&nbsp;";
			}
			echo"</td></tr>";
		}
	}
	$d->close();
 ?>
 </table>
</fieldset>
</td>
</tr>
<tr>
 <td height="100">&nbsp;</td>
</tr>
</table>
</body>
</html>
<script type="text/javascript">

//var f = document.forms[0];
//MaskInput(f.code,"9999");
//]]>
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>
